package com.glsc.ngateway.opmanage.config;

import com.glsc.ngateway.common.base.utils.TrimFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.DispatcherType;

@Configuration
public class FilterConfig {

    /**
     * 去除参数头尾空格过滤器
     *
     * @return
     */
    @Bean
    public FilterRegistrationBean<TrimFilter> trimFilter() {
        FilterRegistrationBean<TrimFilter> registration = new FilterRegistrationBean<>();
        registration.setDispatcherTypes(DispatcherType.REQUEST);
        registration.setFilter(new TrimFilter());
        registration.addUrlPatterns("/*");
        registration.setName("TrimFilter");
        registration.setOrder(Integer.MAX_VALUE - 1);
        return registration;
    }

//    /**
//     * 增加前端访问日志TraceId
//     *
//     * @return
//     */
//    @Bean
//    public FilterRegistrationBean<MdcLogFilter> mdcLogFilter() {
//        FilterRegistrationBean<MdcLogFilter> registration = new FilterRegistrationBean<>();
//        registration.setDispatcherTypes(DispatcherType.REQUEST);
//        registration.setFilter(new MdcLogFilter());
//        registration.addUrlPatterns("/*");
//        registration.setName("MdcLogFilter");
//        registration.setOrder(Integer.MIN_VALUE - 1);
//        return registration;
//    }

}
